import Foundation
import RxSwift
import Moya
import SwiftyJSON

public extension PrimitiveSequence where Trait == SingleTrait, Element == Response {

    func mapJson() -> Single<JSON> {
        return flatMap { resopnse -> Single<JSON> in
            do{
                return .just(try JSON.init(data: resopnse.data))
            }catch let error {
                return .error(error)
            }
        }
    }

    
    func mapAny<T: Codable>(_ object: T.Type) -> Single<T> {
        return flatMap { resopnse -> Single<T> in
            do{
                return .just(try newJSONDecoder().decode(T.self, from: resopnse.data))
            }catch let error {
                return .error(error)
            }
        }
    }
}
